<?php

declare(strict_types=1);

namespace App\Request\auth\Service;

use App\Repository\IRepository;
use Hyperf\Collection\Collection;
use Hyperf\DbConnection\Model\Model;
use Hyperf\DbConnection\Traits\HasContainer;

/**
 * @template T of Model
 * @property IRepository<T> $repository
 */
abstract class IService
{
    use HasContainer;

    public function count(array $params): int
    {
        return $this->repository->count($params);
    }

    public function page(array $params, int $page = 1, int $pageSize = 10): array
    {
        return $this->repository->page($params, $page, $pageSize);
    }

    public function getList(array $paras, array $filed = ["*"]): Collection
    {
        return $this->repository->list($paras, $filed);
    }

    /**
     * @return Model
     */
    public function create(array $data): mixed
    {
        return $this->repository->create($data);
    }

    /**
     * @return Model
     */
    public function save(array $data): mixed
    {
        return $this->create($data);
    }

    /**
     * @return null|mixed|Model
     */
    public function updateById(mixed $id, array $data): mixed
    {
        return $this->repository->updateById($id, $data);
    }

    public function deleteById(mixed $id): int
    {
        return $this->repository->deleteById($id);
    }


    public function findByField(mixed $id, string $field): mixed
    {
        return $this->repository->findByField($id, $field);
    }


    public function existsByWhere(array $params): bool
    {
        return $this->repository->existsByWhere($params);
    }

    public function saveOrUpdate(array $data)
    {
        return $this->repository->saveOrUpdate($data);
    }

    public function deleteByWhere(array $params)
    {
        return $this->repository->deleteByWhere($params);
    }


    public function findById(int $id)
    {
        return $this->repository->findById($id);
    }

    public function findByFilter(array $params)
    {
        return $this->repository->findByFilter($params);
    }

}
